<template>
    <div class="common assessment">
        <innerCommon 
            :location="location"
        >
            <template slot="left">
                <span>评价列表</span>
                <a-input-search class="inputStyle" placeholder="搜索用户名"  v-model="searchValue" enter-button @search="onSearch" />
            </template>
            <div slot="table">
                <a-table 
                    size="middle"
                    :columns="columns" 
                    :data-source="list" 
                    :pagination="pagination"
                    :rowKey="record=>record.id"
                    @change="changePage"
                    :locale="{'emptyText': '暂无数据'}"
                    bordered>
                    <div slot="action" slot-scope="index,record"  class="tableAction">
                        <span @click="toDetail(record.id)">查看详情</span>
                        <confirmBox
                            @handleOk="deleteNews(record)"
                            :typeName="'删除'"
                            :noticeInfo="record.name"
                            :noticeType="'评价'"
                        ></confirmBox>
                    </div>
                </a-table>
            </div>
            </innerCommon>
            <detailModal
                :dataList="dataList"
                :detailBox="detailBox"
                @cancel="detailBox=false"
            ></detailModal>
    </div>
</template>
<script>
const columns=[
    {
        title: '序号',
        dataIndex: 'index',
        width:70
    },{
        title: '用户名',
        dataIndex: 'name',
    },{
        title: '账号',
        dataIndex: 'account',
    },{
        title: '真实姓名',
        dataIndex: 'realname',
        width:100
    },{
        title: '所在单位',
        dataIndex: 'instituteName',
    },{
        title: '身份证号码',
        dataIndex: 'idCardNum',
        width:150
    },{
        title: '联系方式',
        dataIndex: 'telephone',
        width:120
    },{
        title: '提交时间',
        dataIndex: 'createTime',
        width:200
    },{
        title: '操作',
        scopedSlots: { customRender: 'action' },
    }
]
import innerCommon from "@/components/common/innerCommon"
import detailModal from "@/components/common/detailModal"
import confirmBox from "@/components/common/confirmBox"
import {getAssessmentDetailApi,searchAssessmentApi,deleteAssessmentApi} from "@/request/api"
export default {
    name:"assessment",
    components:{innerCommon,detailModal,confirmBox},
    watch:{
        searchValue:function(val){
            this.searchValue=val.trim()
        }
    },
    created(){
        this.location=[{
            name:"信息发布管理",
            path:''
        },{
            name:"质量评价",
            path:'/assessment'
        }]
        this.init()
    },
    data(){
        return{
            location:[],
            columns,
            list:[],
            pagination:{pageSize:10,total:0,current:1},
            searchInfo:{
                page:1,
                pageSize:10,
                keyword:''
            },
            dataList:[],
            detailBox:false,
            searchValue:''
        }
    },
    methods:{
        init(){
            this.getToken(searchAssessmentApi,this.searchInfo,res=>{
                this.dealData(res.data.rows,res.data.count)
            })
        },
        onSearch(data){
            this.searchInfo.keyword=data.trim()
            this.changePage({current:1})
        },
        changePage(data){
            this.searchInfo.page=data.current
            this.pagination.current=data.current
            this.init()
        },
        dealData(list,total){
            this.list=list.map((item,index)=>({...item,'index':(this.searchInfo.page-1)*10+index+1,...item.user,'id':item.id}))
            this.pagination.total=total
        },
        deleteNews(data){
            this.getToken(deleteAssessmentApi,{'assessmentId':data.id},res=>{
                this.$message.success(res.message)
                this.init()
            })
        },
        toDetail(id){
            this.getToken(getAssessmentDetailApi,{assessmentId:id},res=>{
                this.detailBox=true
                let info=res.data
                this.dataList=[
                    {
                        'name':'用户名',
                        'info':info.user.name
                    },{
                        'name':'账号',
                        'info':info.user.account
                    },{
                        'name':'真实姓名',
                        'info':info.user.realname
                    },{
                        'name':'身份证号',
                        'info':info.user.idCardNum
                    },{
                        'name':'所在单位',
                        'info':info.user.instituteName
                    },{
                        'name':'联系方式',
                        'info':info.user.telephone
                    },{
                        'name':'建议内容',
                        'info':info.content
                    }
                ]
            })
        },
        
        
    }
}
</script>